package com.jsmtr.rms.controller;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Sheet;
import jxl.Workbook;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.service.IDoMSService;
import com.jsmtr.rms.service.IDoResumeService;
import com.jsmtr.rms.service.IDoSZService;
import com.jsmtr.rms.service.IProjectService;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.EnumTools;
import com.jsmtr.rms.utils.PhoneTools;
import com.jsmtr.rms.utils.StringTools;

@Controller
@RequestMapping("/Do/SZOperation")
public class DoSZOperationController {

    @Resource
    private IUtilService utilService;
    @Resource
    private IDoSZService szService;
    @Resource
    private IDoMSService msService;
    @Resource
    private IDoResumeService doResumeService;
    @Resource
    private IProjectService projectService;

    //[start] 实作管理

    //面试管理主界面
    @RequestMapping("/")
    public String Index(HttpServletRequest request, HttpServletResponse response, Model model) {
        try {
            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);

            //名族
            model.addAttribute("minzu", utilService.optionList("B", "0"));
            //婚否
            model.addAttribute("hunfou", utilService.optionList("D", "0"));
            //政治面貌
            model.addAttribute("zzmm", utilService.optionList("E", "0"));
            //最高学历
            model.addAttribute("education", utilService.optionList("F", "0"));
            //专业技术职务类型
            model.addAttribute("posttype", utilService.optionList("I", "0"));
            //职业资格证
            model.addAttribute("jndj", utilService.optionList("O", "0"));
            /*//招聘岗位
            List<ProjectInfoJobs> jobs = projectService.getjobsbypid(pid);
            StringBuilder dstr = new StringBuilder();
            for (ProjectInfoJobs job : jobs) {
                dstr.append("<option value='" + job.getJobname() + "'>" + job.getJobname() + "</option>");
            }
            model.addAttribute("jobs", dstr);*/

            //招聘岗位
            List<ProjectInfoJobs> projectJobs=utilService.getProjectJobs(pid);
            model.addAttribute("jobs",projectJobs);
            //实作地址
            model.addAttribute("dz", utilService.getAddress());

            List<BaseConfig> _configs = utilService.getConfigs("dxmb");
            StringBuilder str = new StringBuilder();
            for (BaseConfig _config : _configs) {
                str.append("<option value='" + _config.getCode() + "'>" + _config.getName() + "</option>");
            }
            model.addAttribute("dxmb", str);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Do/SZ/Operation/index";
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/getusers")
    public void getusers(HttpServletRequest request, HttpServletResponse response, DUserResume user) {
        try {
            int perpage = Integer.parseInt(request.getParameter("perpage"));
            int page = Integer.parseInt(request.getParameter("page"));
            String flowid = request.getParameter("flowid").trim();

            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto").trim());
            _map.put("workyearfrom", request.getParameter("workyearfrom").trim());
            _map.put("workyearto", request.getParameter("workyearto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto").trim());
            _map.put("flowid", flowid);
            _map.put("szresult", request.getParameter("szresult").trim());
            _map.put("notice", request.getParameter("notice").trim());

            Map<String, Object> map = szService.getSZUsers(page, perpage, user, _map);
            StringBuilder result = new StringBuilder();
            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            if (pageCount != 0) {
               /* Object object = map.get("list");
                for (Object[] _user : (List<Object[]>) object) {*/
                List<HashMap> object = (List<HashMap>)map.get("list");
                for (HashMap<String,Object> _user :  object) {
                    //r.id,s.id as userid,r.code,r.name,r.education,r.workexperience,r.tel,
                    //s.starttime,s.address,s.notice,s.point,s.result,r.fid,r.fqstate,r.jname,s.op8,r.nrid,r.njname
                    result.append("<tr><td><input type='checkbox' id='cb_" + _user.get("ID") + "' value='" + _user.get("ID") + "' /></td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/UserResume/ViewDResume?id="
                            + _user.get("ID") + "'>" + _user.get("NAME")
                            + "</a></td>");
                    result.append("<td>" + _user.get("CARDNO") + "</td>");
                    result.append("<td>" + _user.get("EDUCATIONNAME") + "</td>");
                    result.append("<td>" + _user.get("WORKEXPERIENCE") + "年</td>");
                    result.append("<td>" + _user.get("JNAME") + "</td>");
                    result.append("<td>" + _user.get("TEL") + "</td>");
                    result.append("<td>" + (_user.get("STARTTIME") == null ? "" :_user.get("STARTTIME")) + "</td>");
                    result.append("<td>" + (_user.get("ADDRESS") == null ? "" : _user.get("ADDRESS")) + "</td>");
                    result.append("<td>" + (_user.get("NOTICE") == null ? "" : EnumTools.NoticeState.values()[((BigDecimal) _user.get("NOTICE")).intValue()]) + "</td>");
                    result.append("<td class='link'>" + (_user.get("POINT") == null ? "" : "<a href=\"javascript:viewResult('" + _user.get("USERID") + "');\">" + _user.get("POINT") + "</a>") + "</td>");
                    result.append("<td>" + ( _user.get("RESULT") == null ? "" :  _user.get("RESULT")) + "</td>");
                    result.append("<td>" + ( _user.get("SZREMARK") == null ? "" :  _user.get("SZREMARK")) + "</td>");
                    if (_user.get("OP8") == null || _user.get("OP8").equals("未公布")) {
                        result.append("<td>"+ (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")) + "</td>");
                        result.append("<td class='true'><span>未公布</span></td>");
                    } else {
                        result.append("<td>"+"最近登录："+ (_user.get("LOGINTIME")==null?"":_user.get("LOGINTIME").toString())+"<br/>个人情况：" + (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")) + "</td>");
                        result.append("<td class='false'><span>已公布</span></td>");
                    }

                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQID").equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.get("NRID") != null) {
                            result.append("<td class='ytj'><span title='" + _user.get("NRID") + "'>已推荐</span></td></tr>");
                        } else {
                            if (_user.get("RESULT") == null) {
                                result.append("<td class='true'><span>未完成</td></tr>");
                            } else {
                                if (_user.get("RESULT").equals("结果未生成")) {
                                    result.append("<td class='true'><span>未完成</td></tr>");
                                } else if (_user.get("RESULT").equals("未通过")) {
                                    result.append("<td class='false'><span>已完成</td></tr>");
                                } else {
                                    if (_user.get("FID").equals(flowid)) {
                                        result.append("<td class='true'><span>未完成</td></tr>");
                                    } else {
                                        result.append("<td class='false'><span>已完成</td></tr>");
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                result.append("<tr><td colspan='16'>未找到符合条件的数据</td></tr>");
            }
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='16'>读取数据失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }

    }

    //[end]

    //[start] 实作安排
    @SuppressWarnings({"rawtypes", "unchecked"})
    @RequestMapping(value = "/PlanAction", method = RequestMethod.POST)
    public void PlanAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加实作的人员！", "no", response);
            } else {
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String starttime = request.getParameter("starttime").trim();//面试时间
                String address = request.getParameter("address").trim();//面试地点

                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    if (utilService.FlowIsDoing(fid)) {
                        List list = new ArrayList();
                        List<DoOperationUser> editList = new ArrayList<DoOperationUser>();
                        for (String uid : uids) {
                            DoOperationUser cszuser = szService.getSZUser(fid, uid);
                            if (cszuser == null) {
                                DoOperationUser szuser = new DoOperationUser();
                                szuser.setId(UUID.randomUUID().toString());
                                szuser.setAddress(address);
                                szuser.setFid(fid);
                                szuser.setNotice(EnumTools.NoticeState.未发通知.ordinal());
                                szuser.setResult("结果未生成");
                                szuser.setStarttime(starttime);
                                szuser.setUserid(uid);
                                list.add(szuser);
                            } else {
                                if (cszuser.getNotice() == EnumTools.NoticeState.未发通知.ordinal()) {
                                    cszuser.setAddress(address);
                                    cszuser.setStarttime(starttime);
                                    editList.add(cszuser);
                                }
                            }
                        }
                        if (editList.size() > 0 || list.size() > 0) {
                            utilService.editList(editList, list);
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中信息不支持此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败", "no", response);
        }
    }

    //[end]

    //[start] 导出实作安排

    @RequestMapping("/exportplan")
    public void exportPlan(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/vnd.ms-excel");
        String codedFileName = null;
        OutputStream fOut = null;
        try {
            codedFileName = java.net.URLEncoder.encode("实作安排", "UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();

            //[start] 实作安排表头

            HSSFRow headrow = sheet.createRow(0);//创建一行
            HSSFCell headcel0 = headrow.createCell(0);
            headcel0.setCellValue(new HSSFRichTextString("实作编号"));
            HSSFCell headcel1 = headrow.createCell(1);
            headcel1.setCellValue(new HSSFRichTextString("姓名"));
            HSSFCell headcel2 = headrow.createCell(2);
            headcel2.setCellValue(new HSSFRichTextString("性别"));
            HSSFCell headcel3 = headrow.createCell(3);
            headcel3.setCellValue(new HSSFRichTextString("证件号码"));
            HSSFCell headcel4 = headrow.createCell(4);
            headcel4.setCellValue(new HSSFRichTextString("手机"));
            HSSFCell headcel5 = headrow.createCell(5);
            headcel5.setCellValue(new HSSFRichTextString("应聘职位"));
            HSSFCell headcel6 = headrow.createCell(6);
            headcel6.setCellValue(new HSSFRichTextString("实作时间"));
            HSSFCell headcel7 = headrow.createCell(7);
            headcel7.setCellValue(new HSSFRichTextString("实作地点"));
            HSSFCell headcel8 = headrow.createCell(8);
            headcel8.setCellValue(new HSSFRichTextString("实作考核内容"));
            HSSFCell headcel9 = headrow.createCell(9);
            headcel9.setCellValue(new HSSFRichTextString("实作得分"));
            HSSFCell headcel10 = headrow.createCell(10);
            headcel10.setCellValue(new HSSFRichTextString("考官姓名"));
            HSSFCell headcel11 = headrow.createCell(11);
            headcel11.setCellValue(new HSSFRichTextString("备注信息"));

            //[end]

            String[] uids = request.getParameterValues("uid");
            if (uids != null) {
                String fid = request.getParameter("fid").trim();

                List<Object[]> objs = szService.getSZPlan(fid, uids);
                int i = 1;
                for (Object[] obj : objs) {
                    HSSFRow row = sheet.createRow(i);//创建一行
                    for (int j = 0; j < 12; j++) {
                        HSSFCell cell = row.createCell(j);//创建一列
                       // cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                        cell.setCellType(CellType.STRING);
                        cell.setCellValue(new HSSFRichTextString(
                                obj[j] == null ? "" : obj[j].toString()));
                    }
                    i++;
                }
            }
            fOut = response.getOutputStream();
            workbook.write(fOut);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fOut.flush();
                fOut.close();
            } catch (IOException e) {
            }
        }
    }

    //[end]

    //[start] 发短信

    @RequestMapping(value = "/MsgAction", method = RequestMethod.POST)
    public void MsgAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            //String pid = request.getParameter("pid").trim();//招聘方案ID
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码

            BaseUser cuser = utilService.getSessionUser(request);
            if (cuser.getUdept().equals(deptcode)) {
                //流程是否结束
                if (utilService.FlowIsDoing(fid)) {
                    String dxnr = request.getParameter("dxnr").trim();

                    List<Map<String, String>> msgs = new ArrayList<Map<String, String>>();

                    String[] uids = request.getParameterValues("uid");
                    if (uids == null) {
                        utilService.printJsonResult(false, "请选择参加实作的人员！", "no", response);
                        return;
                    }
                    List<Object[]> users = szService.getSZMsgUsers(fid, uids);
                    List<String> sqls = new ArrayList<String>();

                    for (Object[] user : users) {
                        //u.id,r.name,r.tel,u.starttime,u.address,u.notice
                        if (((BigDecimal) user[5]).intValue() == EnumTools.NoticeState.未发通知.ordinal()) {
                            sqls.add("update DoOperation_User set notice='" + EnumTools.NoticeState.已发通知.ordinal() + "' where id='" + user[0] + "'");

                            //-------------短信----------------
                            Map<String, String> _map = new HashMap<String, String>();
                            _map.put("tel", user[2].toString());
                            _map.put("cont", dxnr.replace("{姓名}", user[1].toString()).replace("{时间}", user[3].toString()).replace("{地点}", user[4].toString()));
                            msgs.add(_map);
                        }
                    }
                    if (sqls.size() > 0) {
                        utilService.editSqls(sqls);
                        BaseMessageConfig messageConfig=utilService.getMessageConfig();
                        // 发送短信
                        if (PhoneTools.sendMsg(msgs,messageConfig.getUsername(),messageConfig.getPassword(),messageConfig.getHost())) {
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "短信发送失败！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "无可执行此操作的信息！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
            }

            utilService.printJsonResult(true, "操作成功", "no", response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败", "no", response);
        }
    }

    //[end]

    //[start] 导入实作成绩

    @RequestMapping("/import")
    public String Import(HttpServletRequest request, Model model) {
        try {
            String pid = request.getParameter("pid").trim();//招聘方案ID
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/Do/SZ/Operation/import";
    }


    //上传Excel事件
    @RequestMapping(value = {"/ImportAction"}, method = RequestMethod.POST)
    public void ImportAction(@RequestParam("excel") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        try {
            String exname = StringTools.getFileExtension(file.getOriginalFilename());//扩展名（.xxx）
            if (exname.equals(".xls")) {
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码

                BaseUser usr = utilService.getSessionUser(request);
                if (usr.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List<DoOperationUser> users = getAllByExcel(fid, file.getInputStream());
                        if (users != null && users.size() > 0) {
                            utilService.editList(users);
                            utilService.printJsonResult(true, "操作成功", "no", response);
                        } else {
                            utilService.printJsonResult(false, "无符合条件的信息！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "只能上传后缀为：xls的Excel文件", "no", response);
            }

        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }

    }

    private List<DoOperationUser> getAllByExcel(String fid, InputStream inputStream) {
        try {
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet rs = rwb.getSheet(0);//得到第一个工作表中的数据(人员信息)
            int rows = rs.getRows();//得到所有的行
            List<DoOperationUser> users = new ArrayList<DoOperationUser>();
            for (int i = 1; i < rows; i++) {
                if (rs.getCell(0, i).getContents().length() != 0) {
                    String id = rs.getCell(0, i).getContents().trim();
                    DoOperationUser szUser = szService.getSZUser(id);
                    if (szUser != null
                            && szUser.getFid().equals(fid)) {
                        try {
                            szUser.setCont(rs.getCell(8, i).getContents().trim());
                            szUser.setPoint(rs.getCell(9, i).getContents().trim());
                            szUser.setPointuser(rs.getCell(10, i).getContents().trim());
                            szUser.setBz(rs.getCell(11, i).getContents().trim());
                            int point = Integer.parseInt(rs.getCell(9, i).getContents().trim());
                            if (point >= 90) {
                                szUser.setPointlevel("通过(好[90分以上])");
                                szUser.setResult("通过");
                            }
                            if (point >= 80 && point <= 89) {
                                szUser.setPointlevel("通过(较好[80-89分])");
                                szUser.setResult("通过");
                            }
                            if (point >= 60 && point <= 79) {
                                szUser.setPointlevel("通过(一般[60-79分])");
                                szUser.setResult("通过");
                            }
                            if (point < 60) {
                                szUser.setPointlevel("不通过(59分及以下)");
                                szUser.setResult("未通过");
                            }
                            szUser.setPointdate(new Date());

                            users.add(szUser);
                        } catch (Exception e) {
                            continue;
                        }

                    }
                } else {
                    break;
                }
            }
            return users;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    //[end]

    //[start] 查看实作结果

    @RequestMapping("/viewResult")
    public String ViewResult(HttpServletRequest request, Model model) {
        try {
            //r.jname,r.name,r.sex,u.starttime,u.address,u.cont,u.point,u.pointuser,u.bz
            String[] id = request.getParameterValues("id");
            Object[] objs = szService.getSZResult(id).get(0);
            StringBuilder str = new StringBuilder();
            str.append("<tr><td>应聘岗位：</td><td colspan='7'>" + objs[0] + "</td></tr>");
            str.append("<tr><td width='100'>姓名：</td><td width='100'>" + objs[1] + "</td>");
            str.append("<td width='70'>性别：</td><td width='60'>" + objs[2] + "</td>");
            str.append("<td width='70'>考核时间：</td><td width='140'>" + objs[3] + "</td>");
            str.append("<td width='70'>考核地点：</td><td>" + objs[4] + "</td></tr>");
            str.append("<tr><td>实操考核内容：</td><td colspan='7'>" + objs[5] + "</td></tr>");
            str.append("<tr><td>考官打分：</td><td>" + objs[6] + "</td><td>考核结论：</td><td colspan='5'><div class='radio1'>");
            float point = Float.parseFloat(objs[6].toString());
            if (point >= 90) {
                str.append("通过（<span class='checked'>好 90分以上</span>");
            } else {
                str.append("通过（<span>好 90分以上</span>");
            }
            if (point >= 80 && point <= 89) {
                str.append("&emsp;<span class='checked'>较好 80-89分</span>");
            } else {
                str.append("&emsp;<span>较好 80-89分</span>");
            }
            if (point >= 60 && point <= 79) {
                str.append("&emsp;<span class='checked'>一般 60-79分</span>");
            } else {
                str.append("&emsp;<span>一般 60-79分</span>");
            }
            if (point <= 59) {
                str.append("）&emsp;<span class='checked'>不通过 59分及以下</span>");
            } else {
                str.append("）&emsp;<span>不通过 59分及以下</span>");
            }

            str.append("</div></td></tr>");
            str.append("<tr><td>考官姓名：</td><td colspan='7'>" + objs[7] + "</td></tr>");
            str.append("<tr><td>备注：</td><td colspan='7'>" + objs[8] + "</td></tr>");
            model.addAttribute("result", str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/Do/SZ/Operation/result";

    }

    //[end]

    //[start] 流程扭转到下一步

    @SuppressWarnings({"rawtypes", "unchecked"})
    @RequestMapping(value = "/NextAction", method = RequestMethod.POST)
    public void NextAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] ids = request.getParameterValues("id");//人员信息ID
            if (ids != null) {
                String pid = request.getParameter("pid").trim();//招聘方案ID
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                BaseUser usr = utilService.getSessionUser(request);
                if (usr.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List editlist = new ArrayList();
                        List<DUserResume> users = szService.getResumes(ids);
                        ProjectInfoFlow nFlow = szService.getNextFlow(pid, deptcode, fid);
                        for (DUserResume user : users) {
                            if (user.getFid().equals(fid)
                                    && user.getFqstate().equals("未放弃")
                                    && user.getNrid() == null) {
                                DoOperationUser szuser = szService.getSZUser(fid, user.getId());
                                if (szuser.getResult().equals("已通过")||szuser.getResult().equals("通过")) {
                                    user.setFid(nFlow.getId());
                                    user.setPath(user.getPath() + nFlow.getId() + "/");
                                    editlist.add(user);
                                }
                            }
                        }

                        if (editlist.size() > 0) {
                            nFlow.setState(EnumTools.PlanFlowState.进行中.ordinal());
                            editlist.add(nFlow);

                            utilService.editList(editlist);
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中的信息不能执行此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "请选择人员信息！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]
}
